package midterm;

import java.util.Comparator;

public class Twitterer implements Comparable<Twitterer> {
	private String nic;
	private String actualName;
	private int tweets;
	private int followers;

	public Twitterer(String inRealName, String inNic, int inTweets, int inFollowers) {
		actualName = inRealName;
		nic = inNic;
		tweets = inTweets;
		followers = inFollowers;
	}

	public void addTweets(int amount) {
		tweets += amount;
	}

	public void addFollowers(int howMany) {
		followers += howMany;
	}

	public boolean equals(Object what) {
		Twitterer other = (Twitterer) what;
		return nic.equals(other.nic);
	}

	public int hashCode() {
		return nic.hashCode();
	}

	public String getNic() {
		return nic;
	}

	public int compareTo(Twitterer other) {
		int comparison = followers - other.followers;

		if (comparison != 0) {
			return comparison;
		}

		return actualName.compareTo(other.actualName);

	}

	public int getTweets() {
		return tweets;
	}

	public int getFollowers() {
		return followers;
	}

	public String getName() {
		return nic;
	}

	public String getActualName() {
		return actualName;
	}

	public String toString() {
		return nic + " " + actualName + " " + tweets + " " + followers;
	}

	public static Comparator<Twitterer> byName() {
		return new Comparator<Twitterer>() {
			public int compare(Twitterer a, Twitterer b) {
				return a.tweets - b.tweets;
			}
		};
	}

}